<template>
  <div class="app-container">
    <el-card shadow="never" class="mb20">
      <div class="filter-container">
        <div class="filter-item">
          <label class="radio-label">行为：</label>
          <el-input v-model="listQuery.logName" placeholder="行为" style="width: 200px;" @keyup.enter.native="handleFilter" />
        </div>
        <div class="filter-item">
          <label class="radio-label">记录时间：</label>
          <el-date-picker
            v-model="dateRange"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </div>
        <div class="filter-item">
          <label class="radio-label">操作人：</label>
          <el-input v-model="listQuery.userName" placeholder="操作人" style="width: 200px;" @keyup.enter.native="handleFilter" />
        </div>
        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter"></el-button>
        <el-button class="filter-item" icon="el-icon-refresh-left" @click="handleReset"></el-button>
      </div>
    </el-card>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      row-key="id"
      border
      stripe
      fit
      highlight-current-row>
      <el-table-column prop="logName" label="行为" min-width="200" align="center">
      </el-table-column>
      <el-table-column prop="ip" label="发起的IP地址" min-width="200" align="center">
      </el-table-column>
      <el-table-column prop="httpMethod" label="发起的方法" min-width="200" align="center">
      </el-table-column>
      <el-table-column prop="userName" label="操作人" min-width="200" align="center">
      </el-table-column>
      <el-table-column align="center" label="记录时间" min-width="150">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime | moment('YYYY-MM-DD HH:mm:ss') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作" min-width="80" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" circle icon="el-icon-position" title="部署" @click="handleDeploy(scope.row)"></el-button>
          <el-button type="primary" size="mini" circle icon="el-icon-edit" title="修改" @click="handleEdit(scope.row)"></el-button>
          <el-button type="danger" size="mini" circle icon="el-icon-delete" title="删除" @click="handleRemove(scope.row)"></el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize" @pagination="fetchData" />
  </div>
</template>

<script>
import { getSystemLog } from '@/api/system'
import Pagination from '@/views/workflow/components/Pagination'
import moment from 'moment'

export default {
  components: { 
    Pagination
  },
  data() {
    return {
      total: 0,
      dateRange: '',
      listQuery: {
        logName: '',
        userName: '',
        pageNo: 1,
        pageSize: 10
      },
      list: [],
      listLoading: true
    }
  },
  filters: {},
  created() {
    
  },
  methods: {
    handleReset() {
      this.listQuery.logName = ''
      this.listQuery.userName = ''
      this.dateRange = ''
      this.handleFilter()
    },
    handleFilter() {
      this.listQuery.pageNo = 1
      this.fetchData()
    },
    fetchData() {
      this.listLoading = true
      const post = {
        ...this.listQuery
      }
      if (this.dateRange && this.dateRange.length === 2) {
        post.startTime = moment(this.dateRange[0]).format('YYYY-MM-DD')
        post.endTime = moment(this.dateRange[1]).format('YYYY-MM-DD')
      }
      getSystemLog(post).then(response => {
        this.total = response.data.total
        this.list = response.data.records
        this.listLoading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>